PROTOCOL_VERSION = 14
UDP_PORT = 1936

class PRIORITY(object):
    LOW         = 0x10
    MED         = 0x40
    HIGH        = 0x80
    CRITICAL    = 0xE0
    VOLATILE    = 0xFF



class ArtBaseMsg(object):
    _fields = {1:'ID', 2:'OpCode'}
    def __init__(self, **kwargs):
        self.ID = kwargs.get('ID')
        self.ProtVerH = 0
        self.ProtVer = PROTOCOL_VERSION
        fields = {}
        cls = self.__class__
        while cls != ArtBaseMsg:
            if hasattr(cls, '_fields'):
                fields.update(cls._fields)
            cls = cls.__bases__[0]
        fields.update(ArtBaseMsg._fields)
        self.fields = fields
        
                
        
class ArtPoll(object):
    OpCode = 0x2000
    _fields = {3:'ProtVerH', 4:'ProtVer', 5:'TalkToMe', 6:'Priority'}
    def __init__(self, **kwargs):
        self.enable_diagnostics = kwargs.get('enable_diagnostics', False)
        self.diagnostics_unicast = kwargs.get('diagnostics_unicast', False)
        self.enable_unsolicited = kwargs.get('enable_unsolicited', True)
        self.Priority = kwargs.get('Priority', PRIORITY.LOW)
        d = {1:'enable_unsolicited', 2:'enable_diagnostics', 3:'diagnostics_unicast'}
        self._talktome = BitwiseInt(src_object=self, src_attrs=d)
    @property
    def TalkToMe(self):
        return self._talktome.value
        
class ArtPollReply(object):
    OpCode = 0x2100
    _fields = {3:'IPAddress', 4:'Port', 5:'VersInfoH', 6:'VersInfo', 
               7:'SubSwitchH', 8:'SubSwitch', 9:'OemHi', 10:'Oem', 
               11:'UbeaVersion', 12:'Status1', 13:'EstaMan', 14:'ShortName'}
